package com.manager.devicemanager.controller;
import com.manager.devicemanager.common.DataSourceNameEnum;
import com.manager.devicemanager.common.Result;
import com.manager.devicemanager.entity.IcBoardType;
import com.manager.devicemanager.vo.ComponentStatusRequestVO;
import org.springframework.util.StringUtils;
import com.manager.devicemanager.service.IIcBoardTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import com.manager.devicemanager.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wpf
 * @since 2025-07-15
 */
@Tag(name = "IcBoardTypeController", description = " 相关接口")
@RestController
@RequestMapping("/icBoardType")
public class IcBoardTypeController {

    @Autowired
    private IIcBoardTypeService iIcBoardTypeService;

    @Operation(summary = "新增")
    @PostMapping("/save")
    public Result<IcBoardType> save(@Parameter(description = "IcBoardType 对象") @RequestBody IcBoardType icBoardType){
       iIcBoardTypeService.save(icBoardType);
        return Result.success(icBoardType);
    }

    @Operation(summary = "按id删除")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@Parameter(description = "记录ID", example = "1") @PathVariable("id") String id){
       iIcBoardTypeService.removeById(id);
        return Result.success(id);
    }

    @Operation(summary = "按id修改")
    @PostMapping("/update/{id}")
    public Result<IcBoardType> update(@Parameter(description = "记录ID", example = "1") @PathVariable("id") Long id, @Parameter(description = "IcBoardType 对象") @RequestBody IcBoardType icBoardType){
        icBoardType.setId(id);
       iIcBoardTypeService.updateById(icBoardType);
        return Result.success(icBoardType);
    }

    @Operation(summary = "按id查询")
    @GetMapping("/get/{id}")
    public Result<IcBoardType> get(@Parameter(description = "记录ID", example = "1") @PathVariable("id") String id){
        IcBoardType icBoardType =iIcBoardTypeService.getById(id);
        return Result.success(icBoardType);
    }

    @Operation(summary = "条件查询带分页")
    @PostMapping("/page")
    public Result<IPage<IcBoardType>> page(@Parameter(description = "查询条件对象") @RequestBody  PageVO<IcBoardType> icBoardTypeQuery){
        int pageNum = icBoardTypeQuery.getPageNum();
        int pageSize = icBoardTypeQuery.getPageSize();
        IcBoardType icBoardType = icBoardTypeQuery.getCondition();
         QueryWrapper<IcBoardType> wrapper =new QueryWrapper<>(icBoardType);
        //if (StringUtils.hasText(icBoardType.getName())) {
          //  wrapper.like("name", icBoardType.getName());
        //}
        IPage<IcBoardType> icBoardTypeList =iIcBoardTypeService.page(new Page<>(pageNum, pageSize),wrapper );
        return Result.success(icBoardTypeList);
    }

    @Operation(summary = "条件查询")
    @PostMapping("/list")
    public Result<List<IcBoardType>> list(@Parameter(description = "IcBoardType 查询条件对象") @RequestBody ComponentStatusRequestVO componentStatusRequestVO){
        List<IcBoardType> icBoardTypeList =iIcBoardTypeService.getAll(DataSourceNameEnum.ICBOARDCONFIG.getDataSourceName()+componentStatusRequestVO.getDatasourceindex());
        return Result.success(icBoardTypeList);
    }
}
